package library.gui.component;

import java.util.HashMap;
import java.util.Map;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.GridPane;

public class InputList extends GridPane{

//	private int left = 60, right = 160
//	private double left = 0.3, right = 1-left;
	private Map<String, TextLine> map = new HashMap<>();
	
//	private class Entry extends HBox{
//		Label label;
//		TextField textField;
//		Entry(String text, boolean sec) {
//			this.setPadding(new Insets(5, 20, 5, 20));
//			label = new Label(text);
////			label.setPrefWidth(left);
//			textField = sec ? new PasswordField() : new TextField();
////			textField.setPrefWidth(right);
//			label.prefWidthProperty().bind(InputList.this.prefWidthProperty().multiply(left));
//			textField.prefWidthProperty().bind(InputList.this.prefWidthProperty().multiply(right));
//			this.getChildren().add(label);
//			this.getChildren().add(textField);
//		}
//	}
	
	public InputList() {
		this.setAlignment(Pos.TOP_CENTER);
	}

	public String get(String key) {
		return map.get(key).getValue();
	}
	
	public InputList setDefaults(String...all) {
		for(int i = 0; i<all.length; i++) {
			((TextLine)this.getChildren().get(i)).setValue(all[i]);
		}
		return this;
	}
	
	private InputList add(String key, boolean sec) {
		InputLine e = new InputLine(key, sec);
		e.prefWidthProperty().bind(this.widthProperty());
		e.setPadding(new Insets(5));
		e.scale(0.2);
		map.put(key, e);
		this.addColumn(0, e);
		return this;
	}
	
	public InputList addKey(String key) {
		return add(key, false);
	}
	
	public InputList addSecretedKey(String key) {
		return add(key, true);
	}
	
	public InputList addChoiceKey(String key, String...all) {
		ChoiceLine e = new ChoiceLine(key, all);
		e.prefWidthProperty().bind(this.widthProperty());
		e.setPadding(new Insets(5));
		e.scale(0.2);
		map.put(key, e);
		this.addColumn(0, e);
		return this;
	}
	
}
